// pages/approval/reward/detail/detail.js
//获取应用实例
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    backImg: app.globalData.iconImgUrl+"arrow-left.svg",
    StatusBar: app.globalData.StatusBar,
    CustomBar: app.globalData.CustomBar,
    backIcon: true,
    title: "审核详情",
    formeImg: [],
    isExamine: false
  },
  examine(type) {
    if (!this.data.isExamine && this.data.audit) {
      console.log(this.data.audit)
      var data = {
        "userCode": wx.getStorageSync('userCode'),
        "id": this.data.id,
        "auditType": type
      },
        that = this

      var tipText = '及格'
      switch (type) {
        case 'pass':
          tipText = '及格'
          break
        case 'undone':
          tipText = '未完成'
          break
        case 'satisfaction':
          tipText = '满意'
          break
      }

      wx.request({
        url: app.globalData.baseUrl + 'reward/audit.do',
        data: data,
        method: 'post',
        success(res) {
          wx.showToast({
            title: tipText + '已提交',
            icon: 'success',
            duration: 2000
          })
          that.setData({
            isExamine: true
          })
        }
      })
    }
    if (!this.data.audit) {
      wx.showModal({
        title: '提示',
        content: '人数还不够，还不能审批',
      })
    }
  },
  pass() {
    this.examine("pass")
  },
  agree() {
    this.examine("satisfaction")
  },
  noAgree() {
    this.examine("undone")
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options.id)
    this.getDetail(options.id)
    this.setData({
      id: options.id
    })
  },
  getDetail(id) {
    const that = this
    wx.request({
      url: app.globalData.baseUrl + 'reward/xsAuditDetails.do',
      method: 'post',
      data: {
        id: id,
        userCode: wx.getStorageSync('userCode')
      },
      success(res) {
        console.log(res)
        const details = res.data.details
        const imgArr = []

        if (details.img1 !== '' && details.img1 !== null) {
          imgArr.push(details.img1)
        }
        if (details.img2 !== '' && details.img2 !== null) {
          imgArr.push(details.img2)
        }
        if (details.img3 !== '' && details.img3 !== null) {
          imgArr.push(details.img3)
        }

        that.setData({
          content: details.content,
          markName: details.markName,
          mark: details.mark,
          markType: details.markType,
          teamNum: details.teamNum,
          formeImg: imgArr,
          audit: res.data.audit
        })
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
  
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})